home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: uu4news.netcom.com!friend!news
- From: rich@kastle.com (Richard Krehbiel)
- Subject: Re: Can I assume the FIRST field of a STRUCT is at OFFSET 0?
- Message-ID: <1996Feb8.175304.3443@friend.kastle.com>
- Sender: news@friend.kastle.com (News)
- Reply-To: rich@kastle.com
- Organization: Kastle Development Associates
- X-Newsreader: Forte Free Agent 1.0.82
- References: <KIN.96Feb7142238@sampras.isi.com>
- Date: Thu, 8 Feb 1996 17:52:42 GMT
-
- kin@isi.com (Kin Cho) wrote:
-
- >I couldn't find reference to this in the K&C book.
- >Is this specified one way or the other in ANSI C?
- >Have you run into a platform where this assumption fails?
-
- >Please email if possible.
-
- The standard says that what you're doing is guaranteed. A pointer to
- a struct "equals" a pointer to it's first member. The first structure
- member must have offset zero, and consecutively declared structure
- members (not including bit fields) must be at increasing offsets, as
- given by the offsetof macro. I depend on this myself.
-
- (BTW the C++ standard agrees so long as the struct is a "Plain Old
- Data Structure" (PODS); i.e. it may not be a derived class and it must
- have no virtual functions. In fact, the offsetof macro is only
- defined for a PODS, a fact I find distressing.)
-
- --
- Richard Krehbiel, Kastle Systems, Arlington VA USA
- rich@kastle.com (work) or richk@mnsinc.com (personal)
-
-